<?php
class AloginForm extends CFormModel
{
	public $username;
	public $password;
	public $rememberMe = 0;
    public $_identity;
	
	public function rules()
	{
		return array(
            array('username,password', 'required'),
            array('username', 'length', 'min'=>5),
            array('username, password', 'length','max'=>255),            
            array('password', 'length', 'min'=>6),
            array('rememberMe', 'numerical'),
            array('password','authenticate')
        );
	}
	
  public function attributeLabels()
    {
        return array(
            'username' => '用户名',
            'password' => '密码',
            'rememberMe' => '两个周内自动登录',       
        );
    }
    
    public function authenticate()
    {
    	$this->_identity = new AdminIdentity($this->username, $this->password);
    	switch($this->getcheckover())
    	{
    		case 1:$this->addError('username', '用户名不存在！');return false;;
    		case 2:$this->addError('password', '用户名与密码不匹配！');return false;
    		case 0:return true;
    		default:$this->addErrors('未知错误！');return false;
    	}
    }
    
    public function  getcheckover(){
    	return $this->_identity->authenticate();
    }
}